package com.ctshk.rpc.air.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.utils.Assert;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.air.dto.AirProductChannelOnlineSelfPlatformDTO;
import com.ctshk.rpc.air.entity.AirProductChannelOnlineSelfPlatform;
import com.ctshk.rpc.air.entity.AirProductSaleStrategy;
import com.ctshk.rpc.air.mapper.AirProductChannelOnlineSelfPlatformMapper;
import com.ctshk.rpc.air.mapper.AirProductSaleStrategyMapper;
import com.ctshk.rpc.air.service.IAirProductChannelOnlineSelfPlatformService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * <p>
 * 机票线上自营自定义权限 服务实现类
 * </p>
 *
 * @author lihang
 * @since 2021-03-09
 */
@DubboService
public class AirProductChannelOnlineSelfPlatformServiceImpl extends ServiceImpl<AirProductChannelOnlineSelfPlatformMapper, AirProductChannelOnlineSelfPlatform> implements IAirProductChannelOnlineSelfPlatformService {
    @Resource
    private AirProductSaleStrategyMapper airProductSaleStrategyMapper;

    @Override
    public AirProductChannelOnlineSelfPlatformDTO getCurrentlyValidData(Long productId, LocalDate date, Long channelId) {
        AirProductSaleStrategy strategy =
                airProductSaleStrategyMapper.getValidDateStrategy(productId, date);
        Assert.nonNull(strategy, SystemError.AIR_PRODUCT_12026);
        //获取线上成本
        AirProductChannelOnlineSelfPlatform one = getOne(Wrappers.<AirProductChannelOnlineSelfPlatform>lambdaQuery()
                .eq(AirProductChannelOnlineSelfPlatform::getStrategyId, strategy.getId())
                .eq(AirProductChannelOnlineSelfPlatform::getChannelId, channelId)
        );
        Assert.nonNull(one, SystemError.AIR_PRODUCT_12026);
        return EntityUtil.copy(one, AirProductChannelOnlineSelfPlatformDTO.class);
    }

}
